import { fromJS } from 'immutable';
import * as constants from './constants';

// allOrderData: 此用户全部订单
// orderedData: 此用户已完成的订单
// orderingData: 此用户未完成的订单
// orderTotal: 订单数量
// totalIncome: 总收入
// balance: 余额
// totalCost: 总支出
const defaultState = fromJS({
  allOrderData: [],
  orderedData: [],
  orderingData: [],
  orderTotal: '',
  totalIncome: '',
  balance: '',
  totalCost: ''
});

export default (state = defaultState, action) => {
  switch(action.type) {
    case constants.GET_ALLORDER:
      return state.merge({
        allOrderData: fromJS(action.allOrderData),
        orderTotal: action.orderTotal,
        totalIncome: action.totalIncome,
        balance: action.balance,
        totalCost: action.totalCost
      });
    case constants.GET_ORDERING:
      return state.set("orderingData", fromJS(action.orderingData));
    case constants.GET_ORDERED:
      return state.set("orderedData", fromJS(action.orderedData));
    default:
      return state;
  }
}